<template>
  <div class="detail-header">
    <div class="header-abs" @click="handleGoBackClick" v-show="showAbs">
      <span class="iconfont goback-icon">&#xe624;</span>
    </div>
    <div
    class="header-fixed"
    v-show="!showAbs"
    :style="opacityStyle"
    >
      <span class="header-fixed-name">景点详情</span>
      <span class="iconfont header-fixed-back-icon" @click="handleGoBackClick">&#xe624;</span>
    </div>
  </div>
</template>

<script>
export default{
  name: 'DetailHeader',
  data () {
    return {
      showAbs: true,
      opacityStyle: {
        opacity: 0
      }
    }
  },
  methods: {
    handleGoBackClick () {
      this.$router.push('/')
    },
    handleScroll () {
      console.log('1')
      const scroll = document.documentElement.scrollTop
      if (scroll > 60) {
        let opacity = scroll / 100
        opacity = opacity > 1 ? 1 : opacity
        this.opacityStyle = { opacity }
        this.showAbs = false
      } else {
        this.showAbs = true
      }
    }
  },
  activated () {
    window.addEventListener('scroll', this.handleScroll)
  },
  deactivated () {
    window.removeEventListener('scroll', this.handleScroll)
  }
}
</script>

<style lang="stylus" scoped>
  .header-fixed
    position: fixed
    top: 0
    left: 0
    right: 0
    bottom: 0
    height: .86rem
    line-height: .86rem
    text-align: center
    color: #ffffff
    font-size: .4rem
    background-color: #00bcd4;
    .header-fixed-name
      margin: 0 1rem
      text-align: center
    .header-fixed-back-icon
      position: absolute
      top: 0
      left: 0
      font-size: .4rem
      text-align: center
  .header-abs
    position: absolute
    top: .1rem
    left: .1rem
    height: .6rem
    width: .6rem
    border-radius: .6rem
    background-color: rgba(0,0,0,.5);
    text-align: center
    line-height: .6rem
    color: #ffffff
    .goback-icon
      font-size: .32rem
      font-weight: 600
      margin-left: -.05rem
</style>
